package com.oig.sys.workflow.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oig.common.module.SysRequest;
import com.oig.sys.security.util.SecurityUtil;
import com.oig.sys.workflow.dto.AutoExeLogDto;
import com.oig.sys.workflow.mapper.TbAutoExeLogMapper;
import com.oig.sys.workflow.vo.AutoExeLogVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "自动化规则执行日志查询")
@RestController
@RequestMapping("/autoRuleLog")
@Slf4j
@RequiredArgsConstructor
public class AutoExeLogController {

    private final TbAutoExeLogMapper autoExeLogMapper;


    @Operation(summary = "查询自动化规则执行日志,弹框分页")
    @PostMapping(value = "/page")
    public PageInfo<AutoExeLogVo> queryAsPage(@RequestBody SysRequest<AutoExeLogDto> sysRequest){
        log.info("page auto rule exe log {}", sysRequest) ;
        AutoExeLogDto autoExeLogDto = sysRequest.getParamDto();
        if (autoExeLogDto==null){
            autoExeLogDto = new AutoExeLogDto();
        }
        if (autoExeLogDto.getRuleId()==null && autoExeLogDto.getTenantId()==null && SecurityUtil.getDefineUserMain().getTenantId()>0){
            autoExeLogDto.setTenantId(SecurityUtil.getDefineUserMain().getTenantId());
        }
        sysRequest.setParamDto(autoExeLogDto) ;
        PageHelper.startPage(sysRequest.getPageNo(), sysRequest.getPageSize());
        List<AutoExeLogVo> list = this.autoExeLogMapper.queryAutoExeLog(sysRequest.getParamDto());
        return new PageInfo<>(list);
    }


}
